﻿using FileToVideo.AddFunc;
using FileToVideo.Config;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FileToVideo.Enums
{
    /// <summary>
    /// 像素分块大小 (1080P视频)
    /// <br/>
    /// 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24, 30, 40, 60, 120
    /// </summary>
    public enum PartSizeMode_1080P
    {
        /// <summary>
        /// 分块未设置
        /// </summary>
        None = 0,

        /// <summary>
        /// 不分块
        /// </summary>
        SIZE_1 = 1,

        /// <summary>
        /// 分块像素2*2
        /// </summary>
        SIZE_2 = 2,

        /// <summary>
        /// 分块像素3*3
        /// </summary>
        SIZE_3 = 3,

        /// <summary>
        /// 分块像素4*4
        /// </summary>
        SIZE_4 = 4,

        /// <summary>
        /// 分块像素5*5
        /// </summary>
        SIZE_5 = 5,

        /// <summary>
        /// 分块像素6*6
        /// </summary>
        SIZE_6 = 6,

        /// <summary>
        /// 分块像素8*8
        /// </summary>
        SIZE_8 = 8,

        /// <summary>
        /// 分块像素10*10
        /// </summary>
        SIZE_10 = 10,

        /// <summary>
        /// 分块像素12*12
        /// </summary>
        SIZE_12 = 12,

        /// <summary>
        /// 分块像素15*15
        /// </summary>
        SIZE_15 = 15,

        /// <summary>
        /// 分块像素20*20
        /// </summary>
        SIZE_20 = 20,

        /// <summary>
        /// 分块像素24*24
        /// </summary>
        SIZE_24 = 24,

        /// <summary>
        /// 分块像素30*30
        /// </summary>
        SIZE_30 = 30,

        /// <summary>
        /// 分块像素40*40
        /// </summary>
        SIZE_40 = 40,

        /// <summary>
        /// 分块像素60*60
        /// </summary>
        SIZE_60 = 60,

        /// <summary>
        /// 分块像素120*120
        /// </summary>
        SIZE_120 = 120,
    }

    /// <summary>
    /// 分块大小扩展方法
    /// </summary>
    public static class PartSizeModeAdd
    {
        /// <summary>
        /// 获取1080P视频所有分块大小
        /// <br />
        /// 0 和 120 不包含在内
        /// <br />
        /// 当前首帧最小数据量见: Json\FirstFramet.json
        /// 120分块时每帧数据量为: 144字节
        /// 60分块时每帧数据量为: 432字节
        /// 当前版本最小数据量为: 257字节 
        /// 因此不建议使用大于60的分块大小
        /// </summary>
        /// <returns></returns>
        public static List<int> Video1080P()
        {
            List<int> ret = new List<int>();
            Enum.GetValues(typeof(PartSizeMode_1080P)).Cast<PartSizeMode_1080P>()
                .ToList().ForEach((part) =>
                {
                    if (part != PartSizeMode_1080P.None && part != PartSizeMode_1080P.SIZE_120)
                    {
                        ret.Add((int)part);
                    }
                });
            return ret;
        }

        /// <summary>
        /// 获取每帧数据大小 (1080P视频)
        /// </summary>
        /// <param name="enum"></param>
        /// <returns></returns>
        public static int FrameSize(this PartSizeMode_1080P @enum)
        {
            int full = Setting.width*Setting.height;
            switch (@enum)
            {
                case PartSizeMode_1080P.None:
                    throw new Exception("分块未设置");
                default:
                    int partSize = (int)@enum;
                    int ret = full / (partSize * partSize);
                    return ret;
            }
        }

        /// <summary>
        /// 获取每帧数据大小 (1080P视频)
        /// </summary>
        /// <param name="enum"></param>
        /// <returns></returns>
        public static int FrameSizeNoError(this PartSizeMode_1080P @enum)
        {
            int full = Setting.width * Setting.height;
            switch (@enum)
            {
                case PartSizeMode_1080P.None:
                    return full;
                default:
                    int partSize = (int)@enum;
                    int ret = full / (partSize * partSize);
                    return ret;
            }
        }
    }
}
